/**
 * 作者：陈文斌 on 2018/12/29.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';
import 'package:crm/component/Login/user_info_section.dart';
import 'package:crm/component/Login/gesture_password_section.dart';
import 'package:crm/component/Login/text_password_section.dart';
import 'package:crm/page/Login/crm_forget_password_page.dart';
import 'package:crm/view/AppBar/custom_app_bar.dart';

const String Title = '登录';

class CRMLoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => _CRMLoginPageState();
}

class _CRMLoginPageState extends State<CRMLoginPage> {
  bool _isGestureLogin = true;

  Widget _loginTypeButton() {
    return Container(
      width: AppScreen.setWidth(70),
      height: 21,
      margin: EdgeInsets.only(top: 30),
      child: InkWell(
        onTap: () {
          _isGestureLogin = !_isGestureLogin;
          setState(() {});
        },
        child: Text(
          _isGestureLogin ? '密码登录>' : '手势登录',
          style: TextStyle(
            color: AppColors.MainColor,
            fontSize: AppFontSizes.Font15,
            fontFamily: AppFontFamilies.PingFangSC,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }

  Widget _forgetPasswordButtonSection() {
    return Container(
      width: AppScreen.setWidth(75),
      height: 21,
      margin: EdgeInsets.only(bottom: 39),
      child: InkWell(
        onTap: () {
          Navigator.push(context,
              MaterialPageRoute(builder: (context) => ForgetPasswordPage()));
        },
        child: Text(
          '忘记密码？',
          style: TextStyle(
            color: AppColors.PlaceholderTextColor,
            fontSize: AppFontSizes.Font15,
            fontFamily: AppFontFamilies.PingFangSC,
            fontWeight: FontWeight.w500,
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      resizeToAvoidBottomInset: false,
      appBar: CustomAppBar(
        title: _isGestureLogin ? '手势登录' : '密码登录',
      ),
      body: GestureDetector(
        behavior: HitTestBehavior.translucent,
        onTap: () {
          FocusScope.of(context).requestFocus(FocusNode());
        },
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Column(
              children: <Widget>[
                UserInfoSection(),
                _isGestureLogin
                    ? GesturePasswordSection()
                    : TextPasswordSection(),
                _loginTypeButton(),
              ],
            ),
            _forgetPasswordButtonSection(),
          ],
        ),
      ),
    );
  }
}
